package com.jqq.threaduse;

import jdk.nashorn.internal.ir.CallNode;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class Thread02 {
    public static void main(String[] args) {
//        Dog dog = new Dog();
//        //dog.start();//这里不能调用start()方法
//        //创建Thread对象，把dog对象(实现Runnable)放入Thread
//        Thread thread = new Thread(dog);
//        thread.start();
        Tiger tiger = new Tiger();
        ThreadProxy threadProxy = new ThreadProxy(tiger);
        threadProxy.start();
    }
}

class Animal{}
class Tiger implements Runnable{
    @Override
    public void run() {
        System.out.println("老虎嗷嗷叫。。"+Thread.currentThread().getName());
    }
}
class ThreadProxy implements Runnable{//把ThreadProxy看作Thread

    private Runnable target = null;

    @Override
    public void run() {
        if(target != null){
            target.run();//动态绑定（运行类型Tiger）
        }
    }

    public ThreadProxy(Runnable target) {
        this.target = target;
    }
    public void start(){
        start0();
    }
    public void start0(){
        run();
    }
}


class Dog implements Runnable{
    int count = 0;
    @Override
    public void run() {
        while(true){
            System.out.println("小狗汪汪叫。。"+(++count)+Thread.currentThread().getName());
            //休眠1s
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(count == 10){
                break;
            }
        }
    }
}